<?php
$this->load->model('sGlobal_model');
?>
<script type="text/javascript" src="<?php echo base_url(); ?>static/select2/select2.min.js" ></script>
<script type="text/javascript" src="<?php echo base_url(); ?>static/js/selectSearchGlobal.js"></script>
<!--
<link type="text/css" href="<?php echo base_url(); ?>ajaxupload/ajaxfileupload.css" rel="stylesheet" /> 
<script src="<?php echo base_url(); ?>ajaxupload/jquery.js" type="text/javascript"></script>
<script src="<?php echo base_url(); ?>ajaxupload/ajaxfileupload.js" type="text/javascript"></script>
-->



<script>
	$(function() {
		$("input[id^='datepicker']").datetimepicker({
			scrollInput: false,
			yearOffset:0,
			lang:'en',
			timepicker:false,
			datepicker:true,
			format:'d/m/Y',
			formatDate:'d/m/Y',
			/*minDate:'-1970/01/01',
			onGenerate:function( ct ){
				$(this).find('.xdsoft_date.xdsoft_weekend')
					.addClass('xdsoft_disabled');
			}*/
		});
	});
</script>
<script>
    function cancel() {
        $.post("<?= site_url() ?>search_global", function(data) {
            window.location = '<?php echo base_url(); ?>search_global/search_global';
        });
    }
    function addServSarKelSave() {
        var desc=$('#pDescription').val();
            var nilai3=desc.trim(); 
        $.post("<?= site_url() ?>services/add_servSarKelSave", {
            //pCType			    :  $('#pCType').val(),
            //pPoboxId    		:  $('#pCtrlID').val(),
        	pNik    			:  $('#pNik').val(),
        	pType    			:  $('#pType').val(),
        	pCriteria    		:  $('#pCriteria').val(),
        	pSubject    		:  $('#pSubject').val(),
        	pDescription  		:  nilai3,
        	pAtasanNik    		:  $('#r_mgrid').val(),
        	pAtasanNama    	    :  $('#r_mgr').val(),
        	pNikFor    		    :  $('#r_id').val(),
        	pRelatedTo    		:  $('#r_relatedid').val()
        }//,
        //function(data) {
        //    window.location = '<?php echo base_url(); ?>search_global/search_global';
        //}
        );
    }
</script>


<?php 
	foreach($getDetail as $a){
	    $aPoboxRelatedTo  	= $a["POBOX_RELATEDTO"];
		$aPoboxId  			= $a["POBOX_ID"];
		$aPoboxNip  		= $a["POBOX_NIP"];
		$aPoboxNikAtasan  	= $a["POBOX_ATASAN_NIK"];
		$aPoboxType 		= $a["POBOX_TYPE"];
		$aPoboxSubject 		= $a["POBOX_SUBJECT"];
		$aPoboxDescription  = $a["POBOX_DESCRIPTION"];
		$aTypeId  			= $a["TYPE_ID"];
		$aTypeDesc  		= $a["MST_TYPE_DESC"];	
		$aPoboxUntukNik  	= $a["POBOX_UNTUK_NIK"];
		
		$cName				= $a["NIKNAME"];
		$cJob				= $a["NIKJOBPOSITION"];
		$cOrg				= $a["NIKORG"];
		$cNameAtasan		= $a["ATASANNAME"];
		
		if(	$aPoboxType == 'KELUHAN'){
			$vPoboxTypeKel = "selected";
		}
		if(	$aPoboxType == 'SARAN'){
			$vPoboxTypeSar = "selected";
		}
 	}
    /*
	if(empty($org)){
		   $org = dbora_getorg("$nik");
	}*/
?>

<div class="container">
<div class="col-md-offset-1" id="top">


<form id="formarea" role="form" method="post" action="" class="form-horizontal"  enctype="multipart/form-data"> 
    <input type="hidden" value="<?php echo $cRequestNo; ?>" id="pCtrlID" name="pCtrlID" />
    <input type="hidden" value="<?php echo $cType; ?>" id="pCType" name="pCType"/>
    <input type="hidden" value="<?php echo $sesNik;?>" id="pNik" name="pNik"/>
    
    
    <div class="col-md-11">
			<div class="panel panel-default">
				<div class="panel-heading">
					<h4 class="panel-title"><b class="caret"></b><b> Request By</b></h4>
				</div>
				<div class="panel-body">
					<div class="col-xs-12 col-sm-6 col-md-6">
						<div class="form-group">
							<label class="control-label col-md-3">Name</span></label>
							<div class="col-md-7">
                            <input type="hidden" value="<?php echo $cName;?>" id="r_nama" class="select2 form-control input-sm" readonly=""/>
                            <input type="hidden" value="<?php echo $aPoboxNikAtasan;?>" id="r_mgrid" class="select2 form-control input-sm" readonly=""/>
                            <input type="hidden" value="<?php echo $cNameAtasan;?>" id="r_mgr" class="select2 form-control input-sm" readonly=""/>
                            
                            <input type="text" value="" id="r_name" class="select2 form-control input-sm" placeholder="<?php echo $cName;?>"/>
                            </div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3">ID Number</label>
							<div class="col-md-4">
							<input type="text" value="<?php echo $aPoboxUntukNik;?>" id="r_id" class="form-control input-sm" readonly=""/> 
							<!-- Edit by Andi Siswanto ~ before id="r_nik" -->
							</div> 
						</div>
					</div>
					<div class="col-xs-6 col-sm-6 col-md-6">
						<div class="form-group">
							<label class="control-label col-md-4">Departement</label>
							<div class="col-md-7">
							<input type="text" value="<?php echo $cOrg;?>" id="r_dept" class="form-control input-sm" readonly=""/>
							<!-- Edit by Andi Siswanto ~ before id="r_department" -->
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4">Job Position</label>
							<div class="col-md-8">
							<input type="text" value="<?php echo $cJob;?>" id="r_job" class="form-control input-sm" readonly=""/>
							</div>
						</div>
					</div>
				</div>
			</div>
            
            
			<div class="panel panel-default">
				<div class="panel-heading"><h4 class="panel-title"><b class="caret"></b><b> Form</b></h4></div>
				<div class="panel-body">
					<div class="col-sm-6 col-md-6">
						<div class="form-group">
							<label class="col-md-4">Criteria</label>
							<div class="col-md-4">
                                <select id="pCriteria" class="form-control input-sm"> 
                                    <option value="KELUHAN" <?php if($aPoboxType=="KELUHAN"){?>selected=""<?php }?>>Keluhan</option>
									<option value="SARAN" <?php if($aPoboxType=="SARAN"){?>selected=""<?php }?>>Saran</option> 
								</select>
							</div>
						</div>
                        <div class="form-group">
							<label class="col-md-4">Related To</label>
							<div class="col-md-7">
								<input type="text" id="r_relatedname" class="select2 form-control input-sm"/>
                                <input type="hidden" id="r_relatedid" class="form-control input-sm" readonly="" />
							</div>		
						</div>
                        <div class="form-group">
							<label class="col-md-4">Subject</label>
							<div class="col-md-5">
								<input type="text" id="pSubject" class="form-control input-sm" />
							</div>		
						</div>
					</div>
                    
					<div class="col-sm-6 col-md-6">
						<div class="form-group">
							<label class="col-md-5">Type</span></label>
							<div class="col-md-7"> 
                                <select id="pType" class="form-control input-sm"> 
                                    <?php
                                        foreach($getType as $z){
                                            $zMstTypeId   	= $z["MST_TYPE_ID"];
											$zMstTypeDesc  	= $z["MST_TYPE_DESC"];
                                            ?>
                                            <option value="<?php echo $zMstTypeId;?>" <?php if($aTypeId==$zMstTypeId){?>selected=""<?php } ?>><?php echo $zMstTypeDesc;?></option>
                                            <?php
                                        }
                                    ?>
								</select>
							</div>
						</div>
						<div class="form-group">
							<label class="col-md-4">Description</span></label>
							<div class="col-md-8">
								<textarea id="pDescription" class="form-control input-sm" style="min-width:190px;max-width:300px;min-height:100px;max-height:200px;">
                                </textarea>
							</div>
						</div>
					</div>
                    
					<div class="row"> 
                        <div class="col-sm-12">
                            <div class="form-group">
                                <label class="control-label col-md-3"></label>
        						<div class="col-sm-2">
                                    <button type="button" class="btn btn-primary btn-block" onclick="addServSarKelSave();">Submit</button>
                                </div>
                                <div class="col-sm-2">
                                    <button type="button" class="btn btn-default btn-block" onclick="cancel();" >Cancel</button>
                                </div>
    				        </div>
                        </div>                   
                    </div>
				</div>
			</div>
		</div>

</form>
</div>
</div>

<script type="text/javascript">
    $.validator.setDefaults({
        submitHandler: function() {
            $.post("<?= site_url() ?>public_room/insert_dmr", {
                r_id: $('#r_id').val(), 
                r_mgr: $('#r_mgr').val(), 
                courier: $('#courier').val(), 
				category: $('#category').val(), 
				cargo_type: $('#cargo_type').val(), 
				location: $('#lokasi_jemput').val(), 
				timed: $('waktu_jemput').val(), 
				D_Area: $('D_Area').val(), 
				D_Regional: $('D_Regional').val(), 
				lantai: $('#lantai').val(), 
				weight: $('#weight').val(), 
				deskripsi: $('#deskripsi').val() 
            },
            function(data) {
                $('#loader').html(data);
            });
        }
    });

    $(document).ready(function() {
        $("#formuser").keypress(function(e) {
            if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
                $.validator.setDefaults({
                    submitHandler: function() {
                        $.post("<?= site_url() ?>public_room/insert_dmr", {
                            r_id: $('#r_id').val(), 
							r_mgr: $('#r_mgr').val(), 
                			courier: $('#courier').val(), 
							category: $('#category').val(), 
							cargo_type: $('#cargo_type').val(), 
							location: $('#lokasi_jemput').val(), 
							timed: $('waktu_jemput').val(), 
							D_Area: $('D_Area').val(), 
							D_Regional: $('D_Regional').val(), 
							lantai: $('#lantai').val(), 
							weight: $('#weight').val(), 
							deskripsi: $('#deskripsi').val() 
                        },
                        function(data) {
                            $('#loader').html(data);
                        });
                    }
                });
            }
        });

        $("#formuser").validate();
    });

	function getArea()
	{
		var courier_id = {courier_id:$("#courier").val()};
		$.ajax({
				type: "POST",
				url : "<?php echo site_url('public_room/ShowArea');?>",
				data: courier_id,
				success: function(msg){$('#Area').html(msg);}
			});
	};
	
	function getReg(area_name)
	{
			var getarea = {area_name:area_name.value};
			$.ajax({
				type: "POST",
				url : "<?php echo site_url('public_room/ShowRegional');?>",
				data: getarea,
				dataType:'json',
				success: function(data)
				{
					$('#D_Regional').select2({
						id: function(bond){ 
						  //return bond.AREA_ID; //value yang ada di select
                          return bond.REGIONAL_NAME;
                        },
					ajax:({	
						type:"POST",
						dataType:'json',
						url: "<?php echo site_url('public_room/getRegional')?>",
						data: function(term)
						{
							return {
										SearchReg:data,
										term:term
							};
						},
						results: function(bond, page) {return {results: bond.Show_Region, more: (bond.Show_Region && bond.Show_Region.length == 10 ? true: false)}}
						}),
						formatResult: function(bond) {return '<div class="select2-user-result">' + bond.REGIONAL_NAME + '</div>'},
						formatSelection: function(bond){return bond.REGIONAL_NAME},
						initSelection: function(elem, cb){return elem}
					});
				}
			});
	};

</script>


<!-- BISA JALAN JIKA DITARUH DI PALING BAWAH -->
<script>
$("#r_name").change(function()
{
    //alert(this.id.substr(2));    
	var nik = $(this).val();
	var DataString = {id:nik};
	$.ajax({
			type: "POST",
			url : "<?php echo site_url('search_global/globals_nik_detail')?>",
			dataType: 'json',
			data: DataString,
			success: function(data)
			{
				$("#r_id").val(data.DetailEmp.HR_ID);
                $("#r_nama").val(data.DetailEmp.NAME);
                $("#r_mgrid").val(data.DetailEmp.MANAGER_ID);
				$("#r_mgr").val(data.DetailEmp.MANAGER);
				$("#r_dept").val(data.DetailEmp.ORG);
				$("#r_job").val(data.DetailEmp.JOB_POSITION);														
			}
		});
});
</script>
<script>
//SCRIPT INI HARUS DIATAS, TIDAK BOLEH DIBAWAH
$("#r_relatedname").change(function()
{
    //alert(this.id.substr(2));    
	var nik = $(this).val();
	var DataString = {id:nik};
	$.ajax({
			type: "POST",
			url : "<?php echo site_url('search_global/globals_rel_detail')?>",
			dataType: 'json',
			data: DataString,
			success: function(data)
			{
				$("#r_relatedid").val(data.DetailRel.REQUEST_NO);
                $("#r_relatedtype").val(data.DetailRel.TYPE);
                $("#r_relatedurl").val(data.DetailRel.REQ_URL);
                $("#r_relatedrequestor").val(data.DetailRel.REQUESTOR);														
			}
		});
});
</script>